package cn.edu.scau.cmi.wujiaxian.comprehension.client;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.control.TitledPane;
import javafx.scene.layout.ColumnConstraints;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.RowConstraints;
import javafx.scene.layout.VBox;
import javafx.scene.shape.StrokeType;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class DoubleInputDialog extends TitledPane{

	private TextField textField1;
	
	private TextField textField2;
	
	private Button confirm;
	
	public DoubleInputDialog(
			String inputTitle1, String inputTitle2, String title,
			Stage stage) {
		this.setAnimated(false);
		this.setMaxHeight(Double.NEGATIVE_INFINITY);
		this.setWidth(Double.NEGATIVE_INFINITY);
		this.setMinHeight(Double.NEGATIVE_INFINITY);
		this.setMinWidth(Double.NEGATIVE_INFINITY);
		this.setPrefHeight(170);
		this.setPrefWidth(300);
		this.setText(title);
		VBox vBox = new VBox();
		vBox.setPrefHeight(155);
		vBox.setPrefWidth(180);
		GridPane gridPane = new GridPane();
		gridPane.setPrefHeight(148);
		gridPane.setPrefWidth(180);

		ColumnConstraints columnConstraints1 = new ColumnConstraints();
		columnConstraints1.setHgrow(Priority.SOMETIMES);
		columnConstraints1.setMaxWidth(85.2);
		columnConstraints1.setMinWidth(10);
		columnConstraints1.setPrefWidth(180);
		ColumnConstraints columnConstraints2 = new ColumnConstraints();
		columnConstraints2.setHgrow(Priority.SOMETIMES);
		columnConstraints2.setMaxWidth(173.2);
		columnConstraints2.setMinWidth(10);
		columnConstraints2.setPrefWidth(144.4);
		gridPane.getColumnConstraints().addAll(columnConstraints1, columnConstraints2);
		
		RowConstraints rowConstraints1 = new RowConstraints();
		rowConstraints1.setMaxHeight(50);
		rowConstraints1.setMinHeight(10);
		rowConstraints1.setPrefHeight(50);
		rowConstraints1.setVgrow(Priority.SOMETIMES);
		RowConstraints rowConstraints2 = new RowConstraints();
		rowConstraints2.setMaxHeight(50);
		rowConstraints2.setMinHeight(10);
		rowConstraints2.setPrefHeight(50);
		rowConstraints2.setVgrow(Priority.SOMETIMES);
		RowConstraints rowConstraints3 = new RowConstraints();
		rowConstraints3.setMaxHeight(32.2);
		rowConstraints3.setMinHeight(10);
		rowConstraints3.setPrefHeight(20.2);
		rowConstraints3.setVgrow(Priority.SOMETIMES);
		gridPane.getRowConstraints().addAll(rowConstraints1, rowConstraints2, rowConstraints3);
		
		Text text1 = new Text();
		text1.setStrokeType(StrokeType.OUTSIDE);
		text1.setStrokeWidth(0);
		text1.setText(inputTitle1);
		Text text2 = new Text();
		text2.setStrokeType(StrokeType.OUTSIDE);
		text2.setStrokeWidth(0);
		text2.setText(inputTitle2);
		gridPane.add(text1, 0, 0);
		gridPane.add(text2, 0, 1);
		
		textField1 = new TextField();
		textField1.setId("input1");
		textField2 = new TextField();
		textField2.setId("input2");
		gridPane.add(textField1, 1, 0);
		gridPane.add(textField2, 1, 1);
		
		HBox hBox = new HBox();
		hBox.setPrefHeight(100);
		hBox.setPrefWidth(200);
		confirm = new Button();
		confirm.setMnemonicParsing(false);
		confirm.setPrefHeight(23);
		confirm.setPrefWidth(75);
		confirm.setText("确认");
		Button cancel = new Button();
		cancel.setMnemonicParsing(false);
		cancel.setPrefHeight(23);
		cancel.setPrefWidth(75);
		cancel.setText("取消");
		cancel.setOnAction((actionEvent)->{
			stage.close();
		});
		hBox.getChildren().add(confirm);
		hBox.getChildren().add(cancel);
		gridPane.add(hBox, 1, 2);
		
		vBox.getChildren().add(gridPane);
		this.setContent(vBox);
	}

	public TextField getTextField1() {
		return textField1;
	}

	public TextField getTextField2() {
		return textField2;
	}
	
	public void setConfirmButtonAction(EventHandler<ActionEvent> confirmAction) {
		confirm.setOnAction(confirmAction);
	}

}
